<template>
  <el-dialog
    title="编辑内容"
    :visible.sync="dialogVisible"
    :show-close="false"
    :close-on-click-modal="false"
  >
    <el-form
      :rules="rules"
      ref="ruleForm"
      :model="formData"
      label-width="100px"
      size="small"
      class="form-box"
    >
      <el-form-item label="课程名称" prop="title">
        <el-input
          v-model="formData.title"
          placeholder="请输入课程名称"
        ></el-input>
      </el-form-item>
      <el-form-item label="课程等级" prop="level">
        <el-select v-model="formData.level" placeholder="请选择课程等级">
          <el-option label="初级" value="初级"></el-option>
          <el-option label="中级" value="中级"></el-option>
          <el-option label="高级" value="高级"></el-option>
        </el-select>
      </el-form-item>
      <el-form-item label="报名人数" prop="count">
        <el-input
          v-model="formData.count"
          placeholder="请输入报名人数"
        ></el-input>
      </el-form-item>
      <el-form-item label="上线时间" prop="date">
        <el-date-picker
          type="date"
          placeholder="选择日期"
          v-model="formData.date"
          value-format="yyyy-MM-dd"
        ></el-date-picker>
      </el-form-item>
      <el-form-item label="技术栈" prop="type">
        <el-radio-group v-model="formData.type">
          <el-radio label="vue" name="type"></el-radio>
          <el-radio label="react" name="type"></el-radio>
          <el-radio label="node" name="type"></el-radio>
          <el-radio label="小程序" name="type"></el-radio>
          <el-radio label="angular" name="type"></el-radio>
        </el-radio-group>
      </el-form-item>
    </el-form>
    <span slot="footer" class="dialog-footer">
      <el-button @click="$emit('closedialog')" size="small">取消</el-button>
      <el-button
        @click="submitForm('ruleForm')"
        type="primary"
        size="small"
        :loading="loading"
        >确定</el-button
      >
    </span>
  </el-dialog>
</template>
<script  lang='ts'>
import { Component, Vue, Provide, Prop } from 'vue-property-decorator'
import { profilesEdit } from '@/api/dataManage'
@Component({ components: {} })
export default class EditTableDialog extends Vue {
  @Prop(Boolean) dialogVisible!: Boolean // 属性或参数中使用 ！：表示强制解析（告诉typescript编译器，这里一定有值），常用于vue-decorator中的@Prop
  @Prop(Object) formData!: {
    title: String
    type: String
    level: String
    count: String
    date: String
    _id: String
  }
  @Provide() rules: any = {
    title: [{ required: true, message: '请输入课程名称', trigger: 'blur' }],
    level: [{ required: true, message: '请选择课程等级', trigger: 'change' }],
    count: [{ required: true, message: '请输入报名人数', trigger: 'blur' }],
    date: [
      {
        type: 'string',
        required: true,
        message: '请选择日期',
        trigger: 'change',
      },
    ],
    type: [
      {
        required: true,
        message: '请选择技术栈',
        trigger: 'change',
      },
    ],
  }
  @Provide() loading: boolean = false
  created() {
    // console.log(this.dialogVisible)
    // console.log(this.formData)
  }
  // 确定
  submitForm(formName: any) {
    let _this = this as any
    ;(this.$refs[formName] as any).validate((valid: boolean) => {
      if (valid) {
        this.loading = true
        profilesEdit({ id: this.formData._id })
          .then((res: any) => {
            this.loading = false
            this.$emit('closedialog')
            _this.$message({
              message: res.data.msg,
              type: 'success',
            })
          })
          .catch((err: any) => {
            this.loading = false
          })
      }
    })
  }
}
</script>
 <style  lang='scss' scoped>
</style>